package com.txd.mofa.login;

import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.kongzue.baseframework.interfaces.Layout;
import com.kongzue.baseframework.util.JumpParameter;
import com.kongzue.baseframework.util.Preferences;
import com.txd.mofa.R;
import com.txd.mofa.adapter.ViewPagerAdp;
import com.txd.mofa.base.BaseAty;
import com.txd.mofa.net.NetUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * 创建时间： 2019/2/25 10:00
 * 功能描述： 引导页
 * 联系方式：1037438704@qq.com
 *
 * @author dell-pc
 */
@Layout(R.layout.aty_boot_page)
public class BootPageAty extends BaseAty {
    private ViewPager viewPager;
    private ViewPagerAdp viewPagerAdp;
    private List<Fragment> fragments;
    private LinearLayout ll_buttom;


    @Override
    public void initViews() {
        super.initViews();
        bottonNavigationBarUtil();
        ll_buttom = findViewById(R.id.ll_buttom);
        viewPager = findViewById(R.id.viewPager);
        fragments = new ArrayList<>();
        ll_buttom.setVisibility(View.GONE);

        Preferences.getInstance().set(me,"tongyi","tongyi",1);

    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    public void initDatas(JumpParameter paramer) {
        for (int i = 0; i < 3; i++) {
            BootPageFgt fgt = new BootPageFgt();
            Bundle bundle = new Bundle();
            bundle.putInt("index", i);
            fgt.setArguments(bundle);
            fragments.add(fgt);
        }
        viewPagerAdp = new ViewPagerAdp(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(viewPagerAdp);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int index, float positionOffset, int positionOffsetPixels) {
                for (int i = 0; i < fragments.size(); i++) {
//                    ll_buttom.getChildAt(i).setBackgroundResource(index == i ? R.drawable.dot_focus : R.drawable.dot_normal);
                }
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        initlndicator();
    }

    /**
     * 初始化指示器
     */
    private void initlndicator() {
        int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                10f, getResources().getDisplayMetrics());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, width);
        lp.rightMargin = 2 * width;
        for (int i = 0; i < fragments.size(); i++) {
            View view = new View(this);
            view.setId(i);
//            view.setBackgroundResource(i == 0 ? R.drawable.dot_focus : R.drawable.dot_normal);
            view.setLayoutParams(lp);
            ll_buttom.addView(view, i);
        }
    }

    @Override
    public void setEvents() {

    }
}
